<template>
  <div class="login-container">
    <div class="logo3"></div>
    <img src="@/assets/logo3.png" class="logo4"  alt=""/>
    <div class="form-box">
      <div class="form-header">
        <div class="logo"></div>
        <div class="logo-name">
          Welcome to Askjina
        </div>
        <div class="form-content">
          <el-form :model="loginForm" :rules="rules" ref="loginFormRef">
            <el-form-item prop="email">
              <el-input v-model="loginForm.email" size="large" placeholder="Input email address">
                <template #prefix>
                  <el-icon><User /></el-icon>
                </template>
              </el-input>
            </el-form-item>
            <el-form-item prop="password">
              <el-input type="password" v-model="loginForm.password" size="large" placeholder="Input password">
                <template #prefix>
                  <el-icon><Lock /></el-icon>
                </template>
              </el-input>
            </el-form-item>
            <div class="forgot-button"  style="width: 100%;text-align: right">
              <el-button type="text" style="padding-right: 0" @click="editPassword">Forgot password</el-button>
            </div>
            <el-button @click="login" class="login-button" size="large" type="primary" v-loading="isLoading">Login</el-button>
            <div style="width: 100%;text-align: center;font-size: 16px">
             <span> Don't have an account? </span>
              <el-button type="text" style="" @click="toRe">Sign in</el-button>
            </div>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref } from 'vue'
import { useRouter } from "vue-router";
import {ElMessage} from "element-plus";
const router = useRouter()
const loginFormRef = ref(null)
// 登录表单
const loginForm = ref({
  email: '',
  password: '',
})
const rules = ref({
  email: [
    { required: true, message: 'Please input email address', trigger: 'blur' },
    { type: 'email', message: 'Please input correct email address', trigger: 'blur' }
  ],
  password: [
    { required: true, message: 'Please input password', trigger: 'blur' }
  ],
})
import { useStore } from 'vuex'
import {Lock, User} from "@element-plus/icons-vue";
const store = useStore()
const isLoading = ref(false)
// 登录
const login = () => {
  loginFormRef.value.validate(async (valid) => {
    if (!valid) {
      return
    }
    isLoading.value = true
    try {
      await store.dispatch('login', loginForm.value)
    }
    catch (e) {
      isLoading.value = false
    }
    isLoading.value = false
    await router.push('/home')
  })

}
const editPassword =  () => {
  router.push({
    path: '/user/password'
  })
}
// 去注册
const toRe = () => {
  try {
    console.log('去注册')
    router.push('/user/register')
  }
   catch (e) {
     console.log(e)
   }
}

</script>
<style lang="scss">
.login-container {
  background-image: url("~@/assets/背景.png");
  background-repeat: no-repeat;
  width: 100%;
  height: 100%;
  background-size: cover;
  position: relative;
  .logo3 {
    display: initial;
    position: absolute;
    left: 125px;
    top: 50%;
    transform: translateY(-50%);
    width: 837px;
    height: 432px;
    background-image: url("~@/assets/logo3.png");
    background-repeat: no-repeat;
    background-size: 100% 100%;
  }
  .logo4  {
    display: none;
  }
  .el-input {
    --el-component-size-large: 48px;
    --el-border-radius-base:8px;
  }
  .el-input--large {
    font-size: 16px;
  }
  .form-box {
    position: absolute;
    top: 50%;
    transform: translateY(-55%);
    right: 10%;
    width: 550px;
    background-color: #ffffff;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    padding:80px;
    border-radius: 14px;
    .form-header {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      .logo {
        width: 60px;
        height: 60px;
        background-image: url("~@/assets/logo2.png");
        background-repeat: no-repeat;
        background-size: 100% 100%;
      }
      .logo-name {
        font-weight: bold;
        font-size: 32px;
        text-align: center;
        padding-top: 20px;
        padding-bottom: 48px;
      }
    }
  }
  .form-content {
    width: 100%;
    .login-button {
      width: 100%;
      margin: 40px 0;
    }
  }

}

//  媒体查询小于768px
@media (max-width: 768px) {

  .login-container {
    background-image: url("~@/assets/h5_bg.png");
    background-repeat: no-repeat;
    background-size: 100% 100%;
    .form-box {
      width: 90%;
      left: 50%;
      right: initial;
      top: 165px;
      transform: translateX(-50%);
      padding: 40px 16px;
      .form-header {
        .logo-name {
          font-size: 18px;
          padding-top: 16px;
          padding-bottom: 30px;
        }
        .logo {
          width: 32px;
          height: 32px;
        }
      }
      .form-content {
        .forgot-button {
          margin-top: -10px;
        }
      }
    }
    .logo3 {
      display: none;
    }
    .logo4 {
      display: initial;
      position: absolute;
      left: 50%;
      top: 10px;
      transform: translateX(-50%);
      width: 269px;
    }
  }
}
</style>
